package com.zou.music_downloader.utils;

import com.zou.music_downloader.bean.SearchSugestionBean;
import com.zou.music_downloader.bean.SimpleSearchSugestionEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zou on 2016/3/11.
 */
public class HandleSugestionBean {
    public static List<SimpleSearchSugestionEntity> castToSugestionEntity(SearchSugestionBean searchSugestionBean) {
        List<SimpleSearchSugestionEntity> mylist = new ArrayList();

        List<SearchSugestionBean.SongEntity>   song   = searchSugestionBean.getSong();
        List<SearchSugestionBean.AlbumEntity>  album  = searchSugestionBean.getAlbum();
        List<SearchSugestionBean.ArtistEntity> artist = searchSugestionBean.getArtist();

        if (song != null) {
            for (int i = 0; i < Math.min(3, song.size()); i++) {
                mylist.add(castSong(song.get(i)));
            }

        }

        if (album != null) {
            for (int i = 0; i < Math.min(2, album.size()); i++) {
                mylist.add(castAlbum(album.get(i)));
            }
        }

        if (artist != null) {
            for (int i = 0; i < Math.min(3, artist.size()); i++) {
                mylist.add(castArtist(artist.get(i)));
            }
        }


        return mylist;
    }

    static SimpleSearchSugestionEntity castAlbum(SearchSugestionBean.AlbumEntity albumEntity) {
        return new SimpleSearchSugestionEntity(1, albumEntity.getAlbumname() + " - " + albumEntity.getArtistname(), albumEntity.getAlbumid());
    }

    static SimpleSearchSugestionEntity castSong(SearchSugestionBean.SongEntity songEntity) {
        return new SimpleSearchSugestionEntity(2, songEntity.getSongname() + " - " + songEntity.getArtistname(), songEntity.getSongid());
    }

    static SimpleSearchSugestionEntity castArtist(SearchSugestionBean.ArtistEntity artistEntity) {
        return new SimpleSearchSugestionEntity(0, artistEntity.getArtistname(), artistEntity.getArtistid());
    }

    public static List<SimpleSearchSugestionEntity> castToResultEntity(SearchSugestionBean searchSugestionBean) {
        List<SimpleSearchSugestionEntity> mylist = new ArrayList();

        List<SearchSugestionBean.SongEntity>   song   = searchSugestionBean.getSong();
        List<SearchSugestionBean.AlbumEntity>  album  = searchSugestionBean.getAlbum();
        List<SearchSugestionBean.ArtistEntity> artist = searchSugestionBean.getArtist();

        if (song != null) {
            mylist.add(new SimpleSearchSugestionEntity(5, "", ""));
            for (int i = 0; i < song.size(); i++) {
                mylist.add(castSong(song.get(i)));
            }

        }

        if (album != null) {
            mylist.add(new SimpleSearchSugestionEntity(4, "", ""));

            for (int i = 0; i < album.size(); i++) {
                mylist.add(castAlbum(album.get(i)));
            }
        }

        if (artist != null) {
            mylist.add(new SimpleSearchSugestionEntity(3, "", ""));

            for (int i = 0; i < artist.size(); i++) {
                mylist.add(castArtist(artist.get(i)));
            }
        }


        return mylist;
    }

}
